package com.framework.modules.dataview.service.impl;

import com.framework.modules.chat.service.ChatFriendService;
import com.framework.modules.dataview.entity.*;
import com.framework.modules.dataview.service.ViewChatFriendInfoListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;

import com.framework.modules.dataview.dao.ViewUserDoingGroupForObjectListDao;
import com.framework.modules.dataview.service.ViewUserDoingGroupForObjectListService;


@Service("viewUserDoingGroupForObjectListService")
public class ViewUserDoingGroupForObjectListServiceImpl extends ServiceImpl<ViewUserDoingGroupForObjectListDao, ViewUserDoingGroupForObjectListEntity> implements ViewUserDoingGroupForObjectListService {
    @Autowired
    private ChatFriendService chatFriendService;

    @Autowired
    private ViewChatFriendInfoListService viewChatFriendInfoListService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper wrapper=new EntityWrapper<ViewUserDoingGroupForObjectListEntity>();
        if(params.containsKey("uid")){
            wrapper.eq("uid",params.get("uid")).ne("object_id",params.get("uid"));
        }
        if(params.containsKey("object_id")){
            wrapper.eq("object_id",params.get("object_id"));
        }
        if(params.containsKey("type")){
            wrapper.eq("type",params.get("type"));
        }
        Page<ViewUserDoingGroupForObjectListEntity> page = this.selectPage(
                new Query<ViewUserDoingGroupForObjectListEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public Map<String,Object> stateAttentAndLikeAndLook(String uid) {
        Map<String,Object> result=new HashMap<>();
        //互相关注为好友
        int friendCount=viewChatFriendInfoListService.selectCount(new EntityWrapper<ViewChatFriendInfoListEntity>()
				.eq("uid",uid).eq("state",2));
        //统计
        StatLikeAndAttentUserEntity statLikeAndAttent=chatFriendService.statLikeAndAttent(Integer.parseInt(uid));

        result.put("friend_count",friendCount);
        result.put("fans_count",statLikeAndAttent.getAttentMeCount());
        result.put("my_like_count",statLikeAndAttent.getMyLikeCount());
        result.put("attented_count",statLikeAndAttent.getMyAttentCount());
        result.put("like_me_count",statLikeAndAttent.getLikeMeCount());
        //统计我关注，我喜欢，我看过
        Map<String,StatUserDoingGroupForObject> stateMy=this.baseMapper.stateMyAttentAndLikeAndLook(uid);

        if(stateMy.containsKey("look")){
            result.put("my_look_count",stateMy.get("look")==null?"0":stateMy.get("look").getTotal());
        }
        //统计关注我，喜欢我，看过我
        Map<String,StatUserDoingGroupForObject> stateMe=this.baseMapper.stateAttentAndLikeAndLookMe(uid);

        if(stateMe.containsKey("look")){
            result.put("look_me_count",stateMe.get("look")==null?"0":stateMe.get("look").getTotal());
        }

        return result;
    }

}
